var assert = require('assert');
var should = require('should');
var util = require('util');
var zlib = require('zlib');
var _ = require('lodash');
var roleHandler = require('../../../app/servers/connector/handler/roleHandler');
var config = require('../../config');
var roleModel = require('../../../app/models/roleModel');
var analyze = require('kc-analyze');
var configUtil = require('../../../app/util/configUtil');
var bagModel = require('../../../app/models/bagModel');

suite('测试connector.roleHandler', function () {
    setup(function (done) {
        // 初始化统计模块
        var analyze_config = configUtil.load('analyze');
        var game_config = configUtil.load('game');
        analyze.initialize({
            host: analyze_config.host,
            server_id: game_config.server_id
        });

        roleModel.getByName('test_create_role', function (err, model) {
            if (!!model) {
                model.remove();
            }
            done();
        });
    });

    suite('createRole', function () {
        test('进入副本成功', function (done) {
            var msg = {};
            msg.job_type = 2;
            msg.name = 'test_create_role';

            var session = {};
            session.get = function (key) {
                if (key === 'auth_uid') {
                    return config.uid;
                }
                if (key === 'channel_id') {
                    return 'guest_10000';
                }
            };

            var role_handler = new roleHandler();
            role_handler.createRole(msg, session, function (err, res) {
                done();
            });
        });

        test('auth_uid不存在', function (done) {
            var msg = {};
            msg.job_type = 1;
            msg.name = 'test';

            var session = {};
            session.get = function (key) {
                if (key === 'auth_uid') {
                    return config.uid;
                }
                if (key === 'channel_id') {
                    return 'guest_10000';
                }
            };

            var role_handler = new roleHandler();
            role_handler.createRole(msg, session, function (err, res) {
                done();
            });
        });

        test('job_type错误', function (done) {
            var msg = {};
            msg.job_type = 1;
            msg.name = 'test';

            var session = {};
            session.get = function (key) {
                if (key === 'auth_uid') {
                    return config.uid;
                }
                if (key === 'channel_id') {
                    return 'guest_10000';
                }
            };

            var role_handler = new roleHandler();
            role_handler.createRole(msg, session, function (err, res) {
                done();
            });
        });
    });

    suite('list', function () {
        test('查询角色列表', function (done) {
            var msg = {};
            var session = {};
            session.get = function (key) {
                return 4973;
            }
            session.uid = 0;

            var role_handler = new roleHandler();
            role_handler.list(msg, session, function (err, res) {
                done();
            });
        });
    });
});
